package stark.app.frame.qrcode;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.blankj.utilcode.util.ToastUtils;
import com.google.zxing.Result;
import com.king.zxing.CaptureActivity;

import stark.app.R;
import stark.common.basic.constant.Extra;
import stark.common.basic.utils.IntentUtil;

public class QRCodeScanActivity extends CaptureActivity {

    public static void startForRet(Activity activity, int reqCode) {
        Intent intent = IntentUtil.getIntent(activity, QRCodeScanActivity.class);
        activity.startActivityForResult(intent, reqCode);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_q_r_code_scan;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getCameraScan().setPlayBeep(true).setVibrate(true);
    }

    @Override
    public boolean onScanResultCallback(Result result) {
        getCameraScan().setAnalyzeImage(false);
        ToastUtils.showShort(result.getText());
        Intent data = new Intent();
        data.putExtra(Extra.CONTENT, result.getText());
        setResult(RESULT_OK, data);
        finish();
        return true;
    }
}